home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 December / maximum-cd-2009-12.iso / DiscContents / gimp-2.7.0-i686-setup.exe / {app} / lib / gimp / 2.0 / plug-ins / palette-to-gradient.py < prev    next >
Encoding:
Python Source  |  2009-08-19  |  3.2 KB  |  86 lines

  1. #!/usr/bin/env python
  2. #
  3. # This program is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  15.  
  16. from gimpfu import *
  17.  
  18. gettext.install("gimp20-python", gimp.locale_directory, unicode=True)
  19.  
  20. def make_gradient(palette, num_segments, num_colors):
  21.     gradient = pdb.gimp_gradient_new(palette)
  22.     pdb.gimp_gradient_segment_range_split_uniform(gradient, 0, -1, num_segments)
  23.  
  24.     for color_number in range(0,num_segments):
  25.         if (color_number == num_colors-1):color_number_next = 0
  26.         else: color_number_next = color_number + 1
  27.         color_left = pdb.gimp_palette_entry_get_color(palette,
  28.                                                       color_number)
  29.         color_right = pdb.gimp_palette_entry_get_color(palette,
  30.                                                        color_number_next)
  31.         pdb.gimp_gradient_segment_set_left_color(gradient,
  32.                                                  color_number, color_left,
  33.                                                  100.0)
  34.         pdb.gimp_gradient_segment_set_right_color(gradient,
  35.                                                   color_number, color_right,
  36.                                                   100.0)
  37.     pdb.gimp_context_set_gradient(gradient)
  38.     return gradient
  39.  
  40.  
  41. def palette_to_gradient_repeating(palette):
  42.     num_colors = pdb.gimp_palette_get_info(palette)
  43.     num_segments = num_colors
  44.     return make_gradient(palette, num_segments, num_colors)
  45.  
  46.  
  47. register(
  48.     "python-fu-palette-to-gradient-repeating",
  49.     N_("Create a repeating gradient using colors from the palette"),
  50.     "Create a new repeating gradient using colors from the palette.",
  51.     "Carol Spears, reproduced from previous work by Adrian Likins and Jeff Trefftz",
  52.     "Carol Spears",
  53.     "2006",
  54.     N_("Palette to _Repeating Gradient"),
  55.     "",
  56.     [(PF_PALETTE,  "palette", _("Palette"), "")],
  57.     [(PF_GRADIENT, "new-gradient", "Result")],
  58.     palette_to_gradient_repeating,
  59.     menu="<Palettes>",
  60.     domain=("gimp20-python", gimp.locale_directory)
  61.     )
  62.  
  63.  
  64. def palette_to_gradient(palette):
  65.     num_colors = pdb.gimp_palette_get_info(palette)
  66.     num_segments = num_colors - 1
  67.     return make_gradient(palette, num_segments, num_colors)
  68.  
  69. register(
  70.     "python-fu-palette-to-gradient",
  71.     N_("Create a gradient using colors from the palette"),
  72.     "Create a new gradient using colors from the palette.",
  73.     "Carol Spears, reproduced from previous work by Adrian Likins and Jeff Trefftz",
  74.     "Carol Spears",
  75.     "2006",
  76.     N_("Palette to _Gradient"),
  77.     "",
  78.     [(PF_PALETTE,  "palette", _("Palette"), "")],
  79.     [(PF_GRADIENT, "new-gradient", "Result")],
  80.     palette_to_gradient,
  81.     menu="<Palettes>",
  82.     domain=("gimp20-python", gimp.locale_directory)
  83.     )
  84.  
  85. main ()
  86.